<template>
  <div>
    <el-button type="warning" @click="add">添加</el-button>
    <el-button type="danger">批量删除</el-button>
    <!-- 表格 -->
    <el-table :data="specslist" border style="width: 100%">
      <el-table-column prop="specsname" label="属性名称" width="180">
      </el-table-column>
      <el-table-column prop="name" label="属性值" width="180">
        <template slot-scope="scope">
          <el-tag
            v-for="item in scope.row.attrs"
            :key="item.id"
            type="warning"
            >{{ item }}</el-tag
          >
        </template>
      </el-table-column>
      <el-table-column prop="address" label="状态">
        <template slot-scope="scope">
          <el-tag :type="scope.row.status == 1 ? 'success' : 'warning'">{{
            scope.row.status == 1 ? "启用" : "禁用"
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="medium" @click="edit(scope.row)">编辑</el-button>
          <el-button type="danger" size="medium" @click="remake(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  props: ["specslist"],
  data() {
    return {};
  },
  computed: {},
  created() {},
  mounted() {},
  watch: {},
  methods: {
    add() {
      // 添加按钮|弹出框状态
      this.$emit("add");
    },
    remake(val) {// 删除
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api.postspecsdelete({ id: val.id }).then((res) => {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
          this.$emit("getspecslist")
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    edit(val){ // 编辑数据
      this.$emit('edit',val)
    }
  },
  components: {},
};
</script>

<style scoped lang="scss">
::v-deep .el-tag {
  margin-right: 5px;
  margin-top: 5px;
}
</style>
